package cn.itcast.ks.mapper;

import cn.itcast.ks.pojo.dtos.NotWorkDto;
import cn.itcast.ks.pojo.dtos.ShowWorkDto;
import cn.itcast.ks.pojo.entity.UserStudentAssignment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author mwj
 * @date 2021/12/12
 * @TIME:15:17
 */
@Mapper
public interface UserStudentAssignmentMapper extends BaseMapper<UserStudentAssignment> {

    @Select("SELECT user_student_assignment.* FROM user_student_assignment where user_id in (SELECT `user`.id FROM `user` where class_id=#{classId} and role_id=2) and \n" +
            "assignment_type=#{type} and created_on = #{time}")
    List<UserStudentAssignment> showWorks(@Param("time") Date time, @Param("type") Integer type, @Param("classId") Integer classId);


    @Select("SELECT user_id,count(*) FROM user_student_assignment where created_on BETWEEN #{startTime} and #{endTime} and assignment_type=#{type} and user_id in (SELECT id from `user` where class_id=#{classId} and role_id=2) and `status`=1 GROUP BY user_id;")
    List<Map> findNotWorkByTime(NotWorkDto notWorkDto);
    //todo 如果用showWorkDto应该如何写
    @Select("SELECT * from user_student_assignment where user_id=#{userId} and assignment_type=#{type} and created_on=#{time}")
    List<UserStudentAssignment> findStudentWork(@Param("userId") Integer userId, @Param("time") Date time, @Param("type") Integer type);

    @Update("UPDATE user_student_assignment set `status`=#{status} where user_id=#{userId} and assignment_id=#{workId}")
    void submitWork(@Param("workId") Integer workId,@Param("userId") Integer userId,@Param("status") Integer status);
    //@Param("startTime") Date startTime,@Param("endTime") Date endTime,@Param("type") Integer type,@Param("classId") Integer classId
}
